<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" href="../../../css/Semantic-UI-CSS-master/semantic.min.css" />
		<link rel="stylesheet" href="../../../js/layui/css/layui.css" />
		<script src="../../../js/layui/layui.js"></script>
		<script src="../../../js/vue/axios.min.js"></script>
		<script src="../../../js/vue/vue.js"></script>

		<style>
			.container{
				margin-top:80px ;
				margin-left: 90px;
			}
			input{
				margin: 10px;
			}
			.layui-btn{
				margin-left: 110px;
			}
		
		</style>
	</head>
	<body>

		<div id="app" class="layui-form">
			<input type="hidden" v-model="blog_id" />
			<div class="container">

				<div class="layui-inline">
					<label class="layui-form-label" style="width: 100px;">标题：</label>
					<div class="layui-input-inline">
						<input type="text" v-model="blog_title" class="layui-input">
					</div>
				</div>

				<div class="layui-inline">
					<label class="layui-form-label" style="width: 100px;">状态：</label>
					<div class="layui-input-inline">
						<input type="text" v-model="translate_status" disabled="disabled" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label" style="width: 100px;">博客分类:</label>
						<div class="layui-input-inline">

							<select name="blog_category_name" v-model="blog_category_name" lay-verify="required" lay-search="">
								<option v-for="ss in blog_category_names" :value="ss.category_name">{{ss.category_name}}</option>
							</select><br />
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<button class="layui-btn" @click="edit">提交</button>
					<button type="button" class="layui-btn layui-btn-primary"  id="close">关闭</button>
				</div>

			</div>
		</div>
		<!-- layui -->
		<script>
			var $;
			layui.use(['form', 'jquery'], function() {
				$ = layui.jquery;
				var form = layui.form;

				form.on('select', function(data) {
					//alert(data.value);
					vm.blog_category_name = data.value;
				});
			});
			
			layui.use(['form', 'jquery'], function() {
				var $=layui.jquery
			  $("#close").on('click',function(){
				layui.use(['form', 'jquery'], function() {
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
						parent.layer.close(index);
						//关闭父级页面的表格
						parent.layui.table.reload('testReload');
				});
			});
			
			});

			function ssb() {
				layui.use(['form', 'jquery'], function() {
					layer.alert("编辑成功！", function() {
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
						parent.layer.close(index);
						//关闭父级页面的表格
						parent.layui.table.reload('testReload');
					});
				});
			}

			<!-- vue -->
			var href = location.href;
			var index = href.indexOf("=");
			var id = href.substr(index + 1, href.length);
			var vm = new Vue({
				el: "#app",
				data: {
					blog_id: 0,
					blog_title: "",
					blog_status: "",
					translate_status:"",
					blog_category_name: "",
					blog_category_names: [],
					blog_category_id:0,
				},
				mounted: function() {
					this.echo();
					this.categoryAll();
				},
				methods: {
					echo: function() {
						var thsi = this;
						axios.get("/ssb/blog/blogById?id=" + id).then(function(res) {
							var o = res.data;
							thsi.blog_id = o.blog_id;
							thsi.blog_title = o.blog_title;
							thsi.blog_status = o.blog_status;
							if(o.blog_status==1){
								thsi.translate_status="通过";
							}else{
								thsi.translate_status="未通过";
							}
							thsi.blog_category_name = o.blog_category_name;
						}, function(err) {
							console.log(err);
						})
					},
					
					
					categoryAll: function() {
						var thsi = this;
						axios.get("/ssb/category/CategoryAll").then(function(res) {
								var o = res.data;
								thsi.blog_category_names = o;

							}, function(err) {
								console.log(err);
							}

						);
					},
					edit: function() {
						axios.get("/ssb/category/findByName",{
							params:{
							blog_category_name:this.blog_category_name
							}
						}).then(res=>{
							this.blog_category_id=res.data.category_id;
						},err=>{
							console.log(err);
						});
						
						console.log(this.blog_category_id);
						
						axios.get("/ssb/blog/edit", {
							params: {
								'blog_id': this.blog_id,
								'blog_title': this.blog_title,
								'blog_status': this.blog_status,
								'blog_category_name': this.blog_category_name,
								'blog_category_id':this.blog_category_id
							}
						
						}).then((res)=> {
							console.log("2");
							if (res != 0) {
								ssb();
						
							} else {
								alert("失败");
							}
						}, (err) =>{
							console.log(err);
						});
						
						
					}
				},


			});
		</script>
	</body>
</html>
